﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DTO;

namespace DAO
{
    public class HangGuiDAO
    {
        public DataTable LayDSHang()
        {
            DataTable dt = new DataTable();
            SqlConnection cn = DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand("sp_LayDanhSachHangGui", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            cn.Close();
            return dt;
        }
       
        public DataTable loadmancc()
        {
            DataTable dt = new DataTable();
            SqlConnection cn = DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand("sp_LoadMaNCC", cn);
            cmd.CommandType = CommandType.StoredProcedure;
           
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            cn.Close();
            return dt;
        }

        public DataTable loadhoa(int mancc)
        {
            DataTable dt = new DataTable();
            SqlConnection cn = DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand("sp_LoadTenHoa", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaNCC", mancc);

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            cn.Close();
            return dt;
        }
       
        public DataTable loadtext(int ma)
        {
            DataTable dt = new DataTable();
            SqlConnection cn = DataProvider.ConnectionData();
            SqlCommand cmd = new SqlCommand("sp_LayDanhSachTheoMa", cn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaHoa", ma);

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            cn.Close();
            return dt;
        }
        public void ThemHangGui(HangGuiDTO gui)
        {
            try
            {
                SqlConnection cn = DataProvider.ConnectionData();
                string sql = "sp_ThemHangGui";
                SqlCommand cmd = new SqlCommand(sql, cn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@MaHoa", gui.MaHoa);
                cmd.Parameters.Add("@MaNCC", gui.MaNCC);
                cmd.Parameters.Add("@SoLuong", gui.SoLuong);
                cmd.Parameters.Add("@Ngay", gui.Ngay);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
       
        public void Xoa(int ma)
        {
            SqlConnection cn = DataProvider.ConnectionData();
            string sql = "sp_XoaHangGui";
            SqlCommand cmd = new SqlCommand(sql, cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@MaHG", ma);
            cmd.ExecuteNonQuery();
            cn.Close();
        }
    }
}
